var util = require('../../utils/util');
var wxRequest = require('../../utils/wxRequest');
import config from '../../utils/config';
import { $wuxLoading } from '../../dist/index'

var app = getApp();
var that;
var pageInex = 1;

Page({
  data: {
    money: 0,
	empty_msg:app.globalData.empty_msg,
    user:null,
    list : [],
    isLoadMore : false,
    isEnd : false,
    isEmpty:false,
    inputShowed: false,
    inputVal: ""
  },

  onPullDownRefresh:function(){
    pageInex = 1;
    this.start=true;
    that.setData({
      list : [],
      isLoadMore : false,
      isEnd : false,
      isEmpty:true
    });
    util.showLoading();
    that.loadData();
  },
  onReachBottom : function(e,a){
      if(!that.data.isEnd && !that.data.isLoadMore && !that.data.isEmpty){
          that.loadData();
      }
  },

  onLoad:function(){
	util.loading = $wuxLoading();
    pageInex = 1;
    that = this;
	that.loadData();
    
  }
  ,loadData:function(){
	util.showLoading();
	app.getUserInfo()
    .then(res => {
        var params = {
          pageIndex: pageInex,
          pageSize: app.globalData.defaultPageSize
        }
        return wxRequest.postRequest(config.GetChargeListByUid, params)
    })
    .then(res => {
        res = res.list;

        if(pageInex==1 && res.length==0){
            that.setData({
              isLoadMore : false,
              isEnd : false,
              isEmpty :true,
            });
            return;
        }

        if(res.length > 0){
          pageInex++;

          for(var i in res){
           
          }
          var data = that.data.list.concat(res);   
          that.setData({
              list : data,
              isLoadMore : false,
			  isEmpty :false
          });
        }
        
        if(res.length < app.globalData.defaultPageSize || res.length == 0 ){
          that.setData({
            isLoadMore : false,
            isEnd : true,
			isEmpty :false
          });
        }

    })
    .catch(res => {
        util.alert_catch(res.message);
    })
    .finally(function (res) {
        util.hideLoading();
    });
  }
 
   

})
